package com.dehui.traders.ui.market.rank;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.ui.market.rankdetail.RankDetailActivity;
import com.dehui.traders.ui.stockdetail.StocksDetailActivity;
import com.dehui.traders.utils.BaseRecyclerAdapter;
import com.dehui.traders.utils.SmartViewHolder;

import java.util.Collection;
import java.util.List;

public class RankAdapter extends BaseRecyclerAdapter<PlateListBean> {

    private final Activity context;

    public RankAdapter(Collection<PlateListBean> collection, Activity context) {
        super(collection, R.layout.list_item_rank_market);
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, PlateListBean model, int position) {
        TextView tvTitle = holder.findViewById(R.id.tv_title);
        ListView lvRank = holder.findViewById(R.id.lv_rank_detail);
        TextView tvMore = holder.findViewById(R.id.tv_more);

        tvTitle.setText(model.name);

        List<PlateListBean.PlateData> data = model.data;
        RankItemAdapter itemAdapter = new RankItemAdapter(context, data,model.typeCode);
        lvRank.setAdapter(itemAdapter);

        tvMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RankDetailActivity.start(context,model.typeCode,model.name);
            }
        });

        lvRank.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PlateListBean.PlateData plateData = data.get(position);
                StocksDetailActivity.start(context,"排名",plateData.name,
                        plateData.code.substring(2),String.valueOf(plateData.closePrice),plateData.code.substring(0,2));
            }
        });


    }
}
